package com.example.demo.LeetCode.list;

public class partitionList {
    public static void main(String[] args) {
      ListNode head = createListNode1();
      ListNode dummy1 = new ListNode(-1),dummy2 = new ListNode(-1);
      ListNode p1 = dummy1,p2 = dummy2,p = head;
      int x = 3;
      while (p != null){
          if(p.val < x){
              p1.next = p;
              p1 = p1.next;
          }else{
              p2.next = p;
              p2 = p2.next;
          }
          //断开原链表中每个节点的next指针
          ListNode temp = p.next;
          p.next = null;
          p = temp;
      }
      p1.next = dummy2.next;
      ListNode q = dummy1;
      q = q.next;
      while (q!=null){
          System.out.println(q.val);
          q = q.next;
      }
    }

    private static  ListNode createListNode1(){
        ListNode head1 = new ListNode(1);
        ListNode next1 = new ListNode(2);
        ListNode next2 = new ListNode(2);
        ListNode next3 = new ListNode(3);
        ListNode next4 = new ListNode(4);
        ListNode next5 = new ListNode(5);
        head1.next = next1;
        next1.next = next2;
        next2.next = next3;
        next3.next = next4;
        next4.next = next5;
        return head1;
    }

}
